package org.dodobrowser.utils;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

public class DatabaseUtil 
{
	

    /**
     * Table Name
     */
    private static final String DATABASE_TABLE = null;
    
    private final Context context;
    private DatabaseHelper myDbHelper;
    private SQLiteDatabase myDb;
    
    /**
     * Constructor - takes the context to allow the database to be opened/created
     * 
     * @param ctx the Context within which to work
     */
    public DatabaseUtil(Context Cxt)
    {
    	this.context = Cxt;
    }
    
    /**
     * This method is used to create/open a connection
     * @return instance of DatabaseUtil
     * @throws SQLException
     */
    public DatabaseUtil open() throws SQLException
    {
    	myDbHelper = new DatabaseHelper(context);
    	myDb = myDbHelper.getWritableDatabase();
    	return this;
    }
    
    public DatabaseUtil open(Context context, String name, CursorFactory factory, int version) throws SQLException
    {
    	myDbHelper = new DatabaseHelper(context, name, factory, version);
    	myDb = myDbHelper.getWritableDatabase();
    	return this;
    }
    
    /**
     * This method is used to close the connection
     */
    public void close()
    {
    	myDbHelper.close();
    }
   
}
